package com.jack.controller;

import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.google.common.collect.Maps;
import com.jack.dao.UserRepository;
import com.jack.entity.User;

@RestController
public class UserController {

	@Autowired
	private UserRepository userRepository;
	
	@GetMapping("/{id}")
	public User findOne(@PathVariable("id") Long id){
		User user = userRepository.findOne(id);
		return user;
	}
	
	@GetMapping("/user")
	public User get1( Long id,  String name){
		User user = userRepository.get1(id, name);
		return user;
	}
	
//	@GetMapping("/user2")
//	public User get2( String username,  String name){
//		Map<String, Object> map = Maps.newHashMap();
//		map.put("username", username);
//		map.put("name", name);
//		
//		User user = userRepository.get2(map);
//		return user;
//	}
	
	@PostMapping("/post")
	public User post(User user){
		 User user2 = userRepository.save(user);
		return user2;
	}
}
